import pyttsx3


def speak(text,voice):
	engine = pyttsx3.init()
	engine.setProperty("voice",voice)
	
	engine.say(text) 
	engine.runAndWait()
	engine.stop() 
		

def speak_settings(text, isSave, voices, rate, volue):
	engine = pyttsx3.init() #初始化一个ptttsx3引擎
	rate = engine.getProperty("rate") #获取engine的属性参数方法，有rate，volume,voice,voices,使用setProperty("",value)可以进行设置
	engine.setProperty("rate",rate) #设置rate语音速率为150,范围为0-200
	engine.setProperty("volue",volue) #设置语音音量为1.0，范围为0-1
	print(rate)

	voices = engine.getProperty("voices")    
	engine.setProperty("voice",voices[0].id)

	a = engine.say(text) 
	engine.runAndWait()
	engine.stop() 

	if(int(isSave) == 1):
		engine.save_to_file(text,filename="ceshi.wav",name = 'test') 
		engine.runAndWait() 

def getVoices():
	engine = pyttsx3.init()
	voices = engine.getProperty('voices')
	voiceList = ''
	for voice in voices:
		voiceList = voiceList + voice.id + "-"
	# print("Voices:", str)
	return voiceList


if __name__ == "__main__":
	# text = "hello, this is a test"
	# speak(text, 0)
    getVoices()
